<?php
require_once("xforms/Input.php");
require_once("xforms/Item.php");


class XForms_itemset extends XForms_Core {
  protected $tpl = '{renderItems}';
  function renderItems(){
    $e = new Evaluator();
    $parentNodeName = $this->node->parentNode->nodeName;
    if($parentNodeName=="xforms:select1") {
      $tplItem = '<option {renderValue}>{renderLabel}</option>';
    }
    if($parentNodeName=="xforms:select") {
      $tplItem = '<input {renderReadOnly} type="checkbox" {renderValue}  />
 {renderLabel}<br />';
    }
    $result = '';
    $i=0;
    $bdns=$this->getBindings();
    foreach($bdns as $item) {
      $this->nodesetIndex = $i;
      $result.= $e->evaluate($tplItem, $this);
      $i++;
    }
    return $result;
  }
  function renderLabel(){
    return $this->renderChildNodes(array("xforms:label"));
  }
  function renderValue(){
    return ' value="'.htmlentities($this->renderChildNodes(array("xforms:value")), ENT_QUOTES, 'utf-8').'"';
  }

   function renderReadOnly(){
    $readonly="";
    //$binding = $this->getBinding();
	$binding = $this->getXElement($this->node->parentNode)->getBinding();
    if($binding && $binding->getAttribute("readonly")) {
	$xBinding = $this->getXElement($binding);
      switch($xBinding->evalAttribute("readonly")) {
        case true: $readonly=' readonly="readonly" disabled="disabled"'; break;
        case false: break;
        default:
      }
    }
    return $readonly;
  }
  
}
